(function(){"use strict";var r="https://atomictrackercollector-i5adxi4wfq-uc.a.run.app",h="atomic_pixel_visitor",j="atomic_pixel_session",m="atomic_pixel_queue",x=30*60*1e3;function e(){return Date.now()}function o(){return Math.random().toString(36).substring(2)+e().toString(36)}function y(){try{var e=localStorage.getItem(h);return e||(e=o(),localStorage.setItem(h,e)),e}catch{return o()}}function C(){try{return JSON.parse(localStorage.getItem(j))||null}catch{return null}}function d(e){localStorage.setItem(j,JSON.stringify(e))}function g(){var t={id:o(),lastActivity:e()};return d(t),t}function u(){var t=C();return t?e()-t.lastActivity>x?g().id:(t.lastActivity=e(),d(t),t.id):g().id}function i(){try{return JSON.parse(localStorage.getItem(m))||[]}catch{return[]}}function a(e){localStorage.setItem(m,JSON.stringify(e))}function O(e){var t=i();t.push(e),a(t)}function w(e,t){if(!navigator.onLine||!e||!e.length){t(!1);return}fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(function(n){e.forEach(function(e){console.log("[AtomicPixel] Event sent:",e)}),t(n.ok)}).catch(function(){t(!1)})}function s(){var e=i();if(!e.length)return;w(e,function(e){e&&a([])})}function _(e){for(var t=5381,n=0;n>>0).toString(16)}function b(){var e,t,n,s,o,i,a=localStorage.getItem("atomic_pixel_fingerprint");return a||(t=navigator.userAgent||"",n=screen.width+"x"+screen.height,s=navigator.language||"",o=(new Date).getTimezoneOffset(),i=t+"|"+n+"|"+s+"|"+o,e=_(i),localStorage.setItem("atomic_pixel_fingerprint",e),e)}function c(e){return e=e.toLowerCase(),e.indexOf("fban")>-1||e.indexOf("fbav")>-1?"Facebook Browser":e.indexOf("instagram")>-1?"Instagram Browser":e.indexOf("chrome")>-1&&e.indexOf("edg")===-1&&e.indexOf("opr")===-1?"Chrome":e.indexOf("safari")>-1&&e.indexOf("chrome")===-1?"Safari":e.indexOf("firefox")>-1?"Firefox":e.indexOf("edg")>-1?"Edge":e.indexOf("opr")>-1?"Opera":"Unknown"}function v(e){return e=e.toLowerCase(),e.indexOf("android")>-1?"Android":e.indexOf("ios")>-1?"iOS":e.indexOf("windows nt")>-1?"Windows":e.indexOf("mac os x")>-1?"Mac":e.indexOf("macintosh")>-1?"Mac":e.indexOf("linux")>-1?"Linux":"Unknown"}function p(){return window.innerWidth<768?"mobile":"desktop"}function f(){var e={},t=new URLSearchParams(window.location.search);return e.utm_source=t.get("utm_source")||null,e.utm_medium=t.get("utm_medium")||null,e.utm_campaign=t.get("utm_campaign")||null,e.utm_term=t.get("utm_term")||null,e.utm_content=t.get("utm_content")||null,e.fbclid=t.get("fbclid")||null,e.gclid=t.get("gclid")||null,e.src=t.get("src")||null,e.sck=t.get("sck")||null,e.xcod=t.get("xcod")||null,e}function n(t){var o,n=navigator.userAgent;console.log("location",location.hostname),o={event_type:t,event_timestamp:e(),owner_id:l()||null,project_id:document.body.getAttribute("data-project")||null,funnel_id:document.body.getAttribute("data-funnel")||null,page_id:(document.body.getAttribute("data-page")||"").replace(/^_/,"")||null,page_type:document.body.getAttribute("data-page-type")||null,page_category:document.body.getAttribute("data-page-category")||null,fingerprint_id:b(),session_id:u(),visitor_id:y(),ip:null,country:null,city:null,browser_name:c(n),os_name:v(n),user_agent:n,device_type:p(),url:location.href||null,site:location.hostname||null,referrer:document.referrer||null,origin:f()},console.log("[AtomicPixel] Prepared event:",o),O(o),s()}function l(){try{const e=[...document.querySelectorAll('[class*="a-u-"]')].map(e=>{const t=[...e.classList].find(e=>e.startsWith("a-u-"));return t&&e.dataset.hex?{v:e.dataset.hex,p:+t.replace(/\D+/g,"")}:null}).filter(Boolean).sort((e,t)=>e.p-t.p).map(e=>e.v).join("");if(e)return e}catch{}return document.body.id?.replace("_","")}window.addEventListener("online",s),document.addEventListener("visibilitychange",function(){document.hidden||s()}),document.readyState==="complete"||document.readyState==="interactive"?n("PageView"):document.addEventListener("DOMContentLoaded",function(){n("PageView")});function t(e,t=null){const n="atomic_pixel_debug",o=(new Date).toISOString(),s=`[${o}] ${e}`;try{let e=JSON.parse(localStorage.getItem(n)||"[]");e.push(s),t&&e.push(JSON.stringify(t,null,2)),e.length>50&&(e=e.slice(-50)),localStorage.setItem(n,JSON.stringify(e))}catch(e){console.error("Failed to save debug log:",e)}console.log(s),t&&console.log(t)}document.addEventListener("click",function(s){var i,a,d,h,m,o=s.target.closest(".atomicat-checkout-button");if(console.log("btn",o),!o)for(i=s.target.parentElement;i;){if(i.classList&&i.classList.contains("atomicat-checkout-button")){o=i;break}i=i.parentElement}if(console.log("btn 1",o),o)if(t("[AtomicPixel] Detected InitiateCheckout click"),a=o.tagName==="A"?o:o.querySelector("a"),console.log("anchor",a),!a||!a.getAttribute("target")||a.getAttribute("target")==="_self"){s.preventDefault(),h=navigator.userAgent,m={event_type:"InitiateCheckout",event_timestamp:e(),owner_id:l()||null,project_id:document.body.getAttribute("data-project")||null,funnel_id:document.body.getAttribute("data-funnel")||null,page_id:(document.body.getAttribute("data-page")||"").replace(/^_/,"")||null,page_type:document.body.getAttribute("data-page-type")||null,page_category:document.body.getAttribute("data-page-category")||null,fingerprint_id:b(),session_id:u(),visitor_id:y(),ip:null,country:null,city:null,browser_name:c(h),os_name:v(h),user_agent:h,device_type:p(),url:location.href||null,site:location.hostname||null,referrer:document.referrer||null,origin:f()},t("[AtomicPixel] Sending checkout event",m);try{d=new XMLHttpRequest,d.open("POST",r,!1),d.setRequestHeader("Content-Type","application/json"),d.send(JSON.stringify([m])),d.status===200?t("[AtomicPixel] Checkout event sent successfully"):t("[AtomicPixel] Failed to send checkout event",{status:d.status})}catch(e){t("[AtomicPixel] Error sending checkout event",e)}window.location.href=a.href}else n("InitiateCheckout")}),window.addEventListener("pagehide",function(){var e,t=i();if(!t.length)return;e=new XMLHttpRequest,e.open("POST",r,!1),e.setRequestHeader("Content-Type","application/json"),e.send(JSON.stringify(t)),e.status===200&&a([])}),window.AtomicPixel={track:function(e){n(e)},flush:s,debug:function(){const t="atomic_pixel_debug",e=JSON.parse(localStorage.getItem(t)||"[]");return console.log("=== AtomicPixel Debug Logs ==="),e.forEach(e=>console.log(e)),e},clearDebug:function(){localStorage.removeItem("atomic_pixel_debug"),console.log("AtomicPixel debug logs cleared")}}})()